/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.txweb.table;

import com.jspx.json.NotExpose;
import com.jspx.sober.annotation.Column;
import com.jspx.sober.annotation.IDType;
import com.jspx.sober.annotation.Id;
import com.jspx.sober.table.OperateTable;
import com.jspx.utils.ArrayUtil;
import com.jspx.utils.StringUtil;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: chenyuan
 * Date: 12-6-3
 * Time: 下午11:16
 * 文件上传接口
 */
public abstract class IUploadFile  extends OperateTable {
    final static private String[] imageFileType = {"jpg", "gif", "bmp", "png","jpeg"};
    final static private String[] msOfficeFileType = {"doc", "docx", "ppt", "pptx","xls","xlsx"};
    final static private String[] wpsOfficeFileType = {"wps", "wpt", "et", "dpt"};
    final static private String[] flashFileType = {"swf"};

    @Id(auto = true,type= IDType.serial)
    @Column(caption="ID",notNull = true)
    private long id = 0;

    //用来判断是否已经存在
    @Column(caption="Hash",length=40, notNull=false)
    private String hash = StringUtil.empty;

    @Column(caption="标题",length=250,notNull=true)
    private String title = StringUtil.empty;

    @Column(caption = "关键字", length = 240)
    private String tags = StringUtil.empty;

    @Column(caption="属性",length=1000,notNull=false)
    private String attributes = StringUtil.empty;

    @Column(caption="描述",length=2000)
    private String content = StringUtil.empty;

    @Column(caption="文件路径",length=250,notNull=true)
    private String fileName = StringUtil.empty;

    @Column(caption="类型",length=10)
    private String fileType = StringUtil.empty;

    @Column(caption="大小",notNull=true)
    private long fileSize = 0;

    @Column(caption="排序",notNull=true)
    private int sortType = 0;

    @Column(caption="下载次数",notNull=true)
    private int downTimes = 0;

    @Column(caption="排序日期",notNull=true)
    private Date sortDate = new Date();

    @NotExpose
    @Column(caption="编辑日期",notNull=true)
    private Date lastDate = new Date();

    @NotExpose
    @Column(caption="关联ID",notNull = true)
    private long pid = 0;

    //目前使用在在线编辑图片功能上，一行一个
    @NotExpose
    @Column(caption="编辑历史",length=600,notNull=true)
    private String history = StringUtil.empty;


    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getContent()
    {
        return content;
    }

    public void setContent(String content)
    {
        this.content = content;
    }

    public String getFileName()
    {
        return fileName;
    }

    public void setFileName(String fileName)
    {
        this.fileName = fileName;
    }

    public String getFileType()
    {
        return fileType;
    }

    public void setFileType(String fileType)
    {
        this.fileType = fileType;
    }

    public long getFileSize()
    {
        return fileSize;
    }

    public void setFileSize(long fileSize)
    {
        this.fileSize = fileSize;
    }

    public int getSortType()
    {
        return sortType;
    }

    public void setSortType(int sortType)
    {
        this.sortType = sortType;
    }

    public Date getSortDate()
    {
        return sortDate;
    }

    public void setSortDate(Date sortDate)
    {
        this.sortDate = sortDate;
    }

    public Date getLastDate()
    {
        return lastDate;
    }

    public void setLastDate(Date lastDate)
    {
        this.lastDate = lastDate;
    }

    public int getDownTimes() {
        return downTimes;
    }

    public void setDownTimes(int downTimes) {
        this.downTimes = downTimes;
    }

    public boolean isImage()
    {
        return ArrayUtil.inArray(imageFileType, fileType, true);
    }

    public boolean isFlash()
    {
        return ArrayUtil.inArray(flashFileType, fileType, true);
    }

    public String[] getTagsArray()
    {

        return StringUtil.split(tags," ");
    }

    public String getAttributes() {
        if (attributes==null) return StringUtil.empty;
        return attributes;
    }

    public void setAttributes(String attributes) {
        this.attributes = attributes;
    }

    public String getHash() {
        return hash;
    }

    public void setHash(String hash)
    {
        this.hash = hash;
    }

    public long getPid() {
        return pid;
    }

    public void setPid(long pid) {
        this.pid = pid;
    }

    public String getHistory() {
        return history;
    }

    public void setHistory(String history) {
        this.history = history;
    }
}